package leetcode.jianzhioffer;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-20 20:37
 **/
public class JianZhiOffer58 {

    public String reverseLeftWords2(String s, int n) {
        char[] ch = new char[s.length()];
        int i = n;
        int count = 0;
        for (;i < s.length();i++) {
            ch[count++] = s.charAt(i);
        }
        i = 0;
        while (i < n) {
            ch[count++] = s.charAt(i++);
        }
        return new String(ch);
    }

    public String reverseLeftWords3(String s, int n) {
        return s.substring(n) + s.substring(0, n);
    }

    public String reverseLeftWords(String s, int n) {
        StringBuilder builder = new StringBuilder();
        for (int i = n; i < s.length() + n; i++) {
            builder.append(s.charAt(i % s.length()));
        }
        return builder.toString();
    }
}
